﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using NUnit.Framework;
using WWB.DisqusSharp.Infrastructure;
using WWB.DisqusSharp.Infrastructure.HammockWrappers;
using WWB.DisqusSharp.Model.DisqusService;
using WWB.DisqusSharp.Tests.TestUtility;

namespace WWB.DisqusSharp.Tests.DisqusServiceTests
{
    [Explicit("Don't want to hit service repeatedly.")]
    [TestFixture]
    [Category("Integration Tests")]
    public class DisqusServiceGetTests
    {
        private string threadId;
        private string forumId;
        private string user_api_key;
        private IDisqusService theService;

        [TestFixtureSetUp]
        public void Arrange()
        {
            var ts = TestSettingsProvider.GetTestSettings();
            threadId = ts.ThreadId;
            forumId = ts.ForumId;
            user_api_key = ts.ApiKey;
            theService = new HammockDisqusService(user_api_key);
        }

        [Test]
        public void Can_get_user_name()
        {
            theService.GetUserName()
                .IsSuccessfulResult()
                .WithPayload();
        }

        [Test]
        public void Can_get_forum_list()
        {
            var forums = theService.GetForumList()
                .IsSuccessfulResult()
                .WithPayload();
            Debug.WriteLine("Forums:");
            foreach (var frm in forums)
            {
                Debug.WriteLine(frm.Id + ": " + frm.Name);
            }
        }

        [Test]
        public void Can_get_forum_api_key()
        {
            theService.GetForumApiKey(forumId)
                .IsSuccessfulResult()
                .WithPayload();
        }

        [Test]
        public void Can_get_forum()
        {
            theService.GetForumPosts(forumId)
                .IsSuccessfulResult()
                .WithPayload();
        }

        [Test]
        public void Can_get_thread_posts()
        {
            theService.GetThreadPosts(threadId)
                .IsSuccessfulResult()
                .WithPayload();
        }

        [Test]
        public void Can_get_updated_threads()
        {
            theService.GetUpdatedThreads(forumId, DateTime.Now.AddYears(-1))
                .IsSuccessfulResult()
                .WithPayload();
        }

        [Test]
        public void Can_get_thread_list()
        {
            theService.GetThreadList(forumId, new StartLimitArgs())
                .IsSuccessfulResult()
                .WithPayload();
        }


        [Test]
        public void Can_get_num_posts()
        {
            var ret = theService.GetNumPosts(new string[] {threadId})
                .IsSuccessfulResult()
                .WithPayload();
            Assert.That(ret.ForThread(threadId), Is.Not.Null);
        }
    }
}
